<?php

defined('SYSPATH') or die('Access error!');

class Controller_Shopnews extends Controller_Shop_Main
{

    private $news;

    public function before()
    {

        parent::before();
        $this->news = Model::factory('news');
        I18n::set_current_file('news');
    }

    public function action_detail()
    {
        $id = intval($this->request->param('id'));
        if (empty($id) || !$this->news->is_exist(array('id' => $id)))
        {
            $this->request->redirect(Route::get('shop')->uri(array('action' => 'index')));
        }
        $news_detail = $this->news->get_detail_by_id($id);
        //当前位置
        $this->set_category_position($news_detail['category_id']);

        //设置seo
        $this->set_seo(array('title' => $news_detail['title'], 'keywords' => $news_detail['keywords'], 'description' => $news_detail['description']));
        $this->template->assign('pre_news', $this->news->get_pre_news($id, $news_detail['category_id']));
        $this->template->assign('next_news', $this->news->get_next_news($id, $news_detail['category_id']));
        $this->template->assign('data', $news_detail);
        $this->template->view('shop_news_detail');
    }

    public function action_list()
    {
        $id = intval($this->request->param('id'));
        if (empty($id))
        {
            $this->request->redirect(Route::get('shop')->uri(array('action' => 'index')));
        }
        //获取分类下的文章列表
        $news_list = $this->news->get_allnews_list_by_category_id($id,2);
        //获取分类的详细内容
        $category_detail = Model::factory('category')->get_row(array('id'=>$id),'name');
         //当前位置
        $this->set_category_position($id);
        
        //seo相关
        //获取分类下的seo配置
        $this->set_seo($this->category_seo($id));
        $this->template->assign('data',$category_detail);
        $this->template->assign('news_list',$news_list['list']);
        $this->template->assign('page',$news_list['page']);
        $this->template->view('shop_news_list');
    }

}